import { http } from '@/utils/http'
import { baseUrlApi } from './types'
import type { ObjectResult, ArrayResult, Result } from './types'

export type detailType = {
  remain: number
  total: number
  discount: number
  pwd: string
  points: number
  birthday: string
  cards: cardType[]
  shops: shopType[]
  shopName: string
  shopId: string
  shopAddress: string
  shopContact: string
  expire_time: string
  recharge_time: string
  create_time: string
  consume_time: string
  phone: string
  userId: string
}
export type recordType = {
  title: string
  des: string
  _id: string
  create_time: string
}

export type cardType = {
  name: string
  value: number
  expire_time: string
}

export type itemType = {
  itemName: string
  count: number
}
export type shopType = {
  shopId: string
  name: string
}

export type recordDetailType = {
  type: number
  recharge: number
  give: number
  remain: number
  consume: number
  payMethod: string
  create_time: string
  _id: string
  items: itemType[]
  cards: string
}

export const detailApi = () => {
  return http.request<ObjectResult<detailType>>('post', baseUrlApi('/detail'))
}

export const recordsApi = (data: object) => {
  return http.request<ArrayResult<recordType>>('post', baseUrlApi('/records'), { data })
}

export const recordDetailApi = (data: object) => {
  return http.request<ObjectResult<recordDetailType>>('post', baseUrlApi('/record'), { data })
}

export const changeShopApi = (data: object) => {
  return http.request<Result>('post', baseUrlApi('/shop'), { data })
}
